﻿#include "GameObject.h"

namespace DYEngine
{
	GameObject::GameObject() : Node("New GameObject") { }

	GameObject::GameObject(std::string const& pName) : Node(pName) {}

	void GameObject::SetActive(bool pIsActive)
	{
		if (mIsActive == pIsActive) return;

		mIsActive = pIsActive;
		for(auto iter = mComponents.begin(); iter != mComponents.end(); iter++)
		{
			Component* component = *iter;
			if (pIsActive)
				component->Enable();
			else
				component->Disable();
		}
	}

	GameObject::~GameObject()
	{
		for (auto iter = mComponents.begin(); iter != mComponents.end(); iter++)
		{
			Component* comp = (*iter);
			delete comp;
		}

		mComponents.clear();
	}
}
